package com.zhida.smartcontrol.pagectrl.devicedetail.holiday;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.Arrays;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 13:08
 * description:
 */
public class HolidayPresenter extends BasePresenterImpl<HolidayContract.View> implements HolidayContract.Presenter {

    @Override
    public void inidData() {
        List<String> tabs = Arrays.asList(new String[]{"元旦", "春节", "元宵节", "清明节", "劳动节", "端午节", "中秋节", "重阳节", "国庆节"});
        mView.inflateTab(tabs);
    }

    @Override
    public void getName(String dayType, String weekDay) {
        int type = Integer.parseInt(dayType);
        String[] name;
        String[] choose;
        switch (type) {
            case 10:
                name = new String[]{"30、31、1号", "31、1、2号", "1、2、3号"};
                choose = new String[]{"7", "14", "28"};
                break;
            case 11:
                name = new String[]{"除夕到初六", "初一到初七"};
                choose = new String[]{"127", "254"};
                break;
            case 12:
                name = new String[]{"正月十五到正月十七", "正月十四到正月十六", "正月十三到正月十五"};
                choose = new String[]{"28", "14", "7"};
                break;
            case 13:
                name = new String[]{"5、6、7号", "4、5、6号", "3、4、5号"};
                choose = new String[]{"28", "14", "7"};
                break;
            case 14:
                name = new String[]{"1号到3号", "30号到2号", "29号到1号"};
                choose = new String[]{"28", "14", "7"};
                break;
            case 15:
                name = new String[]{"初五到初七", "初四到初六", "初三到初五"};
                choose = new String[]{"28", "14", "7"};
                break;
            case 16:
                name = new String[]{"十五到十七", "十四到十六", "十三到十五"};
                choose = new String[]{"28", "14", "7"};
                break;
            case 17:
                name = new String[]{"1"};
                choose = new String[]{"1"};
                break;
            default:
                name = new String[]{"30号到6号", "1号到7号"};
                choose = new String[]{"127", "254"};
                break;
        }
        int index = -1;
        for (int i = 0; i < choose.length; i++) {
            if (choose[i].equals(weekDay)) {
                index = i;
            }
        }
        if (index != -1)
            mView.showName(name[index]);
    }


    @Override
    public void requestData(String id, int offset) {
        Params params = Params.newBuilder()
                .add("lampSwitchId", id)
                .add("controlDayType", "1" + offset)
                .build();
        mKalleCenter.get(Api.FIND_WAY_DATA_HOLIDAY, params, true,new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                List<HolidayBean> list = JSON.parseArray(result, HolidayBean.class);
                mView.showData(list);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
